import service from './interceptor'
/**
 * 核心函数，可通过它处理一切请求数据，并做横向扩展
*/
function request(url, options = {params: {},headers:{}}, method) {
    return new Promise((resolve, reject) => {
        let data = {};
        if (method === 'get') data = { params: options.params };
        if (method === 'post') data = { data: options.params };
        // console.log(options);
        service({
            url,
            method,
            ...data,
            headers: options.headers
        }).then(res => {
            //此处也可以拥有更多的扩展
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
}


function get(url, options) {
    return request(url, options, 'get')
}
function post(url, options) {
    return request(url, options, 'post')
}

export default {
    get, post
}